<template>
<div class="card-password views-container">
    <div class="wlm-table">
        <div class="wlm-table-hearder-btn">
            <router-link tag="span" to="/application/cardPasswordAdd">
                <el-button size="small" type="primary">创建卡密库</el-button>
            </router-link>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="85px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="卡密库名称：">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.kammi_title" placeholder="请输入卡密库名称" style="width:160px;"></el-input>
                    </el-form-item>
                    <!-- <el-form-item label="卡密类型：">
                        <el-select v-model="tableFormatData.userTable.files.luck_mode" placeholder="请选择" style="width:200px;">
                            <el-option label="全部" value="">
                            </el-option>
                            <el-option label="按时间开奖" :value="1">
                            </el-option>
                            <el-option label="按人数开奖" :value="2">
                            </el-option>
                        </el-select>
                        
                    </el-form-item> -->
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-tabs v-model="tableFormatData.userTable.files.kammi_class" type="card" @tab-click="filesSerch">
                <el-tab-pane label="卡密" name="1"></el-tab-pane>
                <el-tab-pane label="串码" name="2"></el-tab-pane>
            </el-tabs>
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <!-- <el-table-column type="selection" width="55">
                </el-table-column> -->
                <el-table-column prop="date" label="卡密库名称"  >
                    <template slot-scope="scope">
                        <span>{{scope.row.kammi_title}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" :label="tableFormatData.userTable.files.kammi_class=='1'?'已售':'已核销'" >
                    <template slot-scope="scope">
                        <span>{{tableFormatData.userTable.files.kammi_class=='1'?scope.row.sold_num:scope.row.written_off}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" :label="tableFormatData.userTable.files.kammi_class=='1'?'库存':'未核销'" >
                    <template slot-scope="scope">
                        <span>{{tableFormatData.userTable.files.kammi_class=='1'?scope.row.stock_num:scope.row.written_on}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="创建时间">
                    <template slot-scope="scope">
                        <p>{{scope.row.create_time}}</p>
                    </template>
                </el-table-column>
                <el-table-column label="操作" >
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="span" :to="{path:'/application/cardPasswordAdd', query :{ kammi_id:scope.row.kammi_id}}">
                                <el-button type="text">编辑</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <router-link v-if="tableFormatData.userTable.files.kammi_class=='1'" class="wlm-text" tag="span" :to="{path:'/application/cardPasswordEdit', query :{ kammi_id:scope.row.kammi_id}}">
                                <el-button type="text">卡密管理</el-button>
                            </router-link>
                            <router-link v-if="tableFormatData.userTable.files.kammi_class=='2'" class="wlm-text" tag="span" :to="{path:'/application/cardSerialCodeList', query :{ kammi_id:scope.row.kammi_id}}">
                                <el-button type="text">串码管理</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.kammi_id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-e flex-align-c">
                <!-- <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row> -->
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  kammiLists,
  kammiDestroy
} from '@/api/application'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'CardPassword',
  components: {
  },
  data() {
    return {
      blogTitle: '',
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: kammiLists,
            delList: kammiDestroy,
            msgConfig: {
              del: {
                type: 'warning',
                msg: '删除卡密库，对应的商品将做售罄或下架处理，确认删除此卡密库？'
              }
            }
          },
          tableData: [],
          files: {
            kammi_title: '',
            kammi_class: '1',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
  }
}
</script>
